package com.pek.control.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pek.control.entity.ProductEntity;
import com.pek.control.entity.TypeEntity;
import com.pek.control.service.IProductService;
import com.pek.control.service.ITypeService;
import com.pek.util.RestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/type")
public class TypeController {
    @Autowired
    private ITypeService typeService;

    @GetMapping("/list")
    public RestResult<List<TypeEntity>> list() {
        return RestResult.success(typeService.list());
    }

    @GetMapping("/query")
    public RestResult<TypeEntity> query(@RequestParam Integer id) {
        var entity = typeService.getById(id);
        if (entity == null)
            return RestResult.error("产品不存在");
        return RestResult.success(entity);
    }

    @PostMapping("/add")
    public RestResult<String> add(@RequestBody String typeName) {
        if (typeService.getOne(new LambdaQueryWrapper<TypeEntity>()
                .eq(TypeEntity::getName, typeName)) != null) {

        }
        return RestResult.success(null);
    }
}
